export default {
    getCarCount(state) { //商品总数
        let sum = 0
        state.car.forEach(element => {
            sum += element.count
        });
        return sum;
    },
    selectCountSum(state) { //选中态的商品总数和商品总价
        let sum = { count: 0, price: 0 };
        state.car.forEach(e => {
            if (e.select) {
                sum.count += parseInt(e.count);
                sum.price += parseInt(e.count * e.price * 100)
            }
        })
        return sum;
    },
    selectAll(state) { //全选框是否选中
        let flag = true
        flag = state.car.some(e => {
            return e.select === false //如果有一项是没有选中的就返回true
        })
        if (flag) {//true为不选中
            return false
        } else {
            return true
        }
    },
    selectCar(state) { //已经选中的商品
        let car = [];
        state.car.forEach(e => {
            if (e.select) {
                car.push(e)
            }
        })
        return car;
    }
}